package com.chengcheng.tuan.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;

import com.chengcheng.tuan.R;
import com.chengcheng.tuan.R.drawable;
import com.chengcheng.tuan.R.id;
import com.chengcheng.tuan.R.layout;
import com.chengcheng.tuan.fragment.ListFragment;
import com.chengcheng.tuan.fragment.MianFragment;
import com.chengcheng.tuan.map.LocationActivity;
import com.chengcheng.tuan.map.PoiSearchActivity;

public class MainActivity extends FragmentActivity implements OnClickListener {

	private View main;
	private View shangjia;
	private Fragment fm;
	private Fragment fsj;

	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		fm = new MianFragment();
		fsj = new ListFragment();
		setContentView(R.layout.activity_main);
		main = findViewById(R.id.main);
		getSupportFragmentManager().beginTransaction().add(R.id.fragment_1, fm).commit();
		main.setOnClickListener(new OnClickListener() {
			public void onClick(View arg0) {
				((TextView) main).setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.ic_menu_poi_on, 0, 0);
				((TextView) shangjia).setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.ic_menu_deal_off, 0, 0);
				getSupportFragmentManager().beginTransaction().replace(R.id.fragment_1, fm).commit();
			}
		});

		shangjia = findViewById(R.id.shangjia);
		shangjia.setOnClickListener(new OnClickListener() {
			public void onClick(View arg0) {
				((TextView) main).setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.ic_menu_poi_off, 0, 0);
				((TextView) shangjia).setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.ic_menu_deal_on, 0, 0);
				getSupportFragmentManager().beginTransaction().replace(R.id.fragment_1, fsj).commit();
			}
		});
		
		findViewById(R.id.img_location).setOnClickListener(this);
		findViewById(R.id.img_search).setOnClickListener(this);
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
			case R.id.img_location:
				startActivity(new Intent(MainActivity.this, LocationActivity.class)); 
				break;
			case R.id.img_search:
				startActivity(new Intent(MainActivity.this, PoiSearchActivity.class)); 
				break;

			default:
				break;
		}
	}
}
